﻿package mortal.game.view.task.drama.operations
{
    import Message.DB.Tables.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.utils.*;
    import mortal.game.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.player.entity.*;

    public class TaskDramaMonsterScreenCenter extends Object implements ITaskDramaStepCommand
    {
        private var _data:TTaskDrama;
        private var _callback:Function;
        private var timerId:int = -1;

        public function TaskDramaMonsterScreenCenter()
        {
            return;
        }// end function

        public function call(param1:TTaskDrama, param2:Function = null) : void
        {
            this._callback = param2;
            this._data = param1;
            setTimeout(this.callAction, 120, 10);
            return;
        }// end function

        private function callAction(param1:int) : void
        {
            if (this.timerId > 0)
            {
                clearTimeout(this.timerId);
                this.timerId = -1;
            }
            var _loc_2:* = this.getBossByCode(this._data.entity);
            if (_loc_2 != null)
            {
                Game.scene.viewTarget = _loc_2;
                this.finish();
            }
            else
            {
                if (param1 > 0)
                {
                    setTimeout(this.callAction, 20, (param1 - 1));
                    return;
                }
                Alert.show(Language.getString(21169) + this._data.entity);
                this.finish();
            }
            return;
        }// end function

        private function finish() : void
        {
            this.timerId = -1;
            if (this._callback != null)
            {
                this._callback.apply();
                this._callback = null;
            }
            return;
        }// end function

        public function cancel(param1:TTaskDrama, param2:Function = null) : void
        {
            if (this.timerId > 0)
            {
                clearTimeout(this.timerId);
                this.timerId = -1;
            }
            this._callback = param2;
            Game.scene.viewTarget = null;
            this.finish();
            return;
        }// end function

        private function getBossByCode(param1:int) : MonsterPlayer
        {
            var _loc_3:IEntity = null;
            var _loc_4:TBoss = null;
            var _loc_2:* = ThingUtil.entityUtil.entitysMap.allEntitys;
            for each (_loc_3 in _loc_2)
            {
                
                if (_loc_3 is MonsterPlayer)
                {
                    _loc_4 = (_loc_3 as MonsterPlayer).bossInfo;
                    if (_loc_4.code == param1)
                    {
                        return _loc_3 as MonsterPlayer;
                    }
                }
            }
            return null;
        }// end function

        public function dispose() : void
        {
            if (this.timerId > 0)
            {
                clearTimeout(this.timerId);
                this.timerId = -1;
            }
            if (this._callback != null)
            {
                this._callback.apply();
                this._callback = null;
            }
            return;
        }// end function

    }
}
